<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * 地址省市表
*/

class City_mdl extends MY_Model {

	public function __construct() {
        parent::__construct();
        $this->table = 'yhm_city';
    }
	
	static public $treeList = array();
	
	public $class = array(
			'0' => 'countries', //国家
			'1' => 'province', //省
			'2' => 'city',  //市
			'3' => 'area' //区/县
	);

	public function select(){
		return $this->db->get($this->table)->result_array();
	}

	public function get_one(){
		$res = $this->db->get($this->table)->row_array();
		return $res;
	}

	//统计
	public function get_count(){
		return $this->db->count_all_results($this->table);
	}

	//添加
	public function create($data){
		$data['end_time'] = $data['create_time'] = time();
		return $this->db->insert($this->table,$data);
	}
	//修改
	public function update($data){
		return $this->db->update($this->table,$data);
	}
	//删除
	public function delete(){
		return $this->update($data);
	}
	
	//查询地址上级
	public function get_fsort($class_id){
		$this->db->where('class_id',$class_id);
		$res = $this->get_one();
		self::$treeList[$res['class_type']] = $res;
		
		if($res['class_type'] != 0){
			$this->get_fsort($res['class_parent_id']);
		}
		ksort(self::$treeList);
		return self::$treeList;
	}

}